package de.htw.praxisprojekt.actions;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JFileChooser;

import de.htw.praxisprojekt.LineAlgo;
import de.htw.praxisprojekt.LoadSaveAlgoPoints;
import de.htw.praxisprojekt.data.LineFileFilter;

public class SaveAction implements ActionListener{

	private LineAlgo lineAlgo;

	public SaveAction(LineAlgo lineAlgo){
		this.lineAlgo=lineAlgo;
	}

	public void actionPerformed(ActionEvent arg0){
		JFileChooser fileChooser=new JFileChooser(".");
		fileChooser.setFileFilter(new LineFileFilter());
		fileChooser.setAcceptAllFileFilterUsed(false);
		fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
		fileChooser.showSaveDialog((Component)arg0.getSource());
		File selectedFile=fileChooser.getSelectedFile();
		if(selectedFile!=null){
			LoadSaveAlgoPoints.saveAlgoPoints(selectedFile,lineAlgo.getAlgoData().getAlgoPoints());
		}
	}
}